<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class AddRefundFeeToRefundStreamTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('refund_stream', function (Blueprint $table) {
            $table->unsignedInteger('refundFee')->default(0)->comment('退款手续费');
            $table->float('refundFeeRate', 8, 6)->default(0)->comment('退款手续费费率');
        });
        DB::connection('mysql')
            ->raw('update kf_refund_stream set refundFeeRate = 0.0025, refundFee = round(0.0025 * refundPrice, 0) where refundChannel = 4');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('refund_stream', function (Blueprint $table) {
            $table->dropColumn('refundFee');
            $table->dropColumn('refundFeeRate');
        });
    }
}
